package com.ngc.mall.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ngc.mall.common.configure.mybatisPlus.BaseServiceImpl;
import com.ngc.mall.core.enumeration.CouponStatus;
import com.ngc.mall.domain.CouponDomain;
import com.ngc.mall.domain.UserCouponDomain;
import com.ngc.mall.mapper.UserCouponMapper;
import com.ngc.mall.service.IUserCouponService;
import com.ngc.mall.vo.UserCouponSimplifyVO;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserCouponServiceImpl extends BaseServiceImpl<UserCouponMapper, UserCouponDomain> implements IUserCouponService {


    @Override
    public Boolean writeOff(CouponDomain couponDomain, Long userId, Long orderId) {
        return super.update(Wrappers.<UserCouponDomain>lambdaUpdate().eq(UserCouponDomain::getCouponId,couponDomain.getId()).eq(UserCouponDomain::getUserId,userId).isNull(UserCouponDomain::getOrderId).eq(UserCouponDomain::getStatus,1).set(UserCouponDomain::getStatus, CouponStatus.USED.getValue()).set(UserCouponDomain::getOrderId,orderId));
    }

    @Override
    public List<UserCouponSimplifyVO> findAllCollectRecord() {
        return baseMapper.findAllCollectRecord();
    }
}
